﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace Uniloader.Configuration
{
    /// <summary>
    /// Converts an assembly-qualified name to System.Type.
    /// </summary>
    class TypeParser : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType.Equals(typeof(string)))
                return true;
            else
                return base.CanConvertFrom(context, sourceType);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
                return Type.GetType((string)value);
            else
                return base.ConvertFrom(context, culture, value);
        }
    }
}
